<?php


namespace EasySwoole\EasySwoole;


use EasySwoole\EasySwoole\AbstractInterface\Event;
use EasySwoole\EasySwoole\Swoole\EventRegister;
use EasySwoole\Http\GlobalParam\Hook;
use Trois\Init\Init;
use Trois\MainServerRegister\MainServerRegister;

class EasySwooleEvent implements Event
{
    public static function initialize()
    {
        date_default_timezone_set('Asia/Shanghai');
        (new Init())->run();

//        // 配置 session，设置 session 数据文件存储目录为 EASYSWOOLE_TEMP_DIR
//        # $sesionHandler = new FileSession(EASYSWOOLE_TEMP_DIR . '/Session');
//
//        $globalParamHook = new Hook();
//
//        // 如果不需要使用 session 请勿注册
//        // 使用时请先参考 session 章节 https://www.easyswoole.com/HttpServer/session.html，新增 \App\Tools\Session 类文件。
//        # \App\Tools\Session::getInstance($sesionHandler);
//        # $globalParamHook->enableSession(Session::getInstance());
//
//        $globalParamHook->register();
//
//        // onRequest v3.4.x+
//        \EasySwoole\Component\Di::getInstance()->set(\EasySwoole\EasySwoole\SysConst::HTTP_GLOBAL_ON_REQUEST, function (\EasySwoole\Http\Request $request, \EasySwoole\Http\Response $response) use ($globalParamHook) {
//            // 替换全局变量
//            $globalParamHook->onRequest($request, $response);
//        });
//
//        // afterRequest v3.4.x+
//        \EasySwoole\Component\Di::getInstance()->set(\EasySwoole\EasySwoole\SysConst::HTTP_GLOBAL_AFTER_REQUEST, function (\EasySwoole\Http\Request $request, \EasySwoole\Http\Response $response) {
//
//        });

    }

    public static function mainServerCreate(EventRegister $register)
    {
        (new MainServerRegister())->run($register);
    }
}